import { Node } from "cc";
import { ecs } from "db://app-game/libs/ecs/ECS";
import { DBRole } from "../../../common/db/db-role/DBRole";
import { DBRoleType } from "../../../common/db/db-role/DBRole.type";

@ecs.register("RoleModel")
export class RoleModelComp extends ecs.Comp {
  db: DBRole = new DBRole();
  /** 用户Id */
  userId: number = -1;
  _id: number = -1;
  /** 角色编号 */
  get id(): number {
    return this._id;
  }
  set id(val: number) {
    this._id = val;
    this.db.init(val);
    this.data = this.db.data;
  }

  /** 角色节点 */
  node: Node = null!;
  /** 角色数据 */
  data: DBRoleType = null!;

  reset(entity: ecs.Entity): void {
    this.userId = -1;
    this._id = -1;
    this.node = null!;
    this.data = null!;
  }
}
